/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.chl.cid.entities;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;

/**
 *
 * @author sasan
 */
@Entity
public class PurchaseOrder implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @Temporal(javax.persistence.TemporalType.DATE)
    @Column(name="ORDER_DATE")
    private Date date;
    @ManyToOne(cascade={CascadeType.PERSIST})
    @JoinColumn(name = "CUSTOMER_FK")
    Customer customer;
    @OneToMany(mappedBy = "po", fetch = FetchType.EAGER,cascade={CascadeType.PERSIST, CascadeType.REMOVE})
    private List<OrderItem> oItems;


      public PurchaseOrder(){
    }

    public PurchaseOrder(Date date) {
        this.date = date;
    }

    public List<OrderItem> getoItems() {
        return oItems;
    }

    public void setoItems(List<OrderItem> oItems) {
        this.oItems = oItems;
    }

     public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }
    
    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public Long getId() {
        return id;
    }
   
    @Override
    public int hashCode() {
        int hash = 7;
        hash = 50 +hash + (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof PurchaseOrder)) {
            return false;
        }
        PurchaseOrder other = (PurchaseOrder) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "edu.chl.sasanf.jpa.nbp.PurchaseOrder[id=" + id + "]";
    }

}
